<?php

namespace Biz\Models\App;

use Biz\Models\Model;
use Biz\Models\User\User;
use Biz\Models\Passport\Client;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class App extends Model
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'app';

    /**
     * @var array
     */
    protected $fillable = [
        'user_id',
        'client_id',
        'type',
        'status',
    ];

    /**
     * OAuth Client.
     *
     * @var Client
     */
    private $client;

    /**
     * AppSite.
     *
     * @var AppSite
     */
    private $appSite;

    /**
     * @return Client
     */
    public function getClient()
    {
        return $this->client;
    }

    /**
     * @param Client $client
     */
    public function setClient(Client $client)
    {
        $this->client = $client;
    }

    /**
     * 查询OAuth客户端.
     */
    public function client()
    {
        //return $this->hasOne(Client::class, 'id', 'client_id');
        return $this->belongsTo(Client::class, 'client_id', 'id');
    }

    /**
     * @return Client
     */
    public function getAppSite()
    {
        return $this->appSite;
    }

    /**
     * @param AppSite $appSite
     */
    public function setAppSite(AppSite $appSite)
    {
        $this->appSite = $appSite;
    }

    /**
     * 获取user.
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
}
